# 数据处理层Model：实现数据读取、写入
# 从 json 文件读取和写入
import json


def read_data(path):
    with open(path, mode='r', encoding='utf-8') as f:
        data = json.load(f)
    return data


def write_data(data_list, path):
    with open(path, mode='w', encoding='utf-8') as f:
        json.dump(data_list, f, ensure_ascii=False)


if __name__ == '__main__':
    path = r'cashbook.json'
    # 测试一下 read_data()
    print(read_data(path))

    # 测试一下 write_data()
    # bll_list = [
    #     {"date": "2021/8/21 09:00:00", "project": "工资", "sort": "收入", "amount": "20000"},
    #     {"date": "2021/8/21 09:00:00", "project": "聚餐", "sort": "支出", "amount": "-200"}
    # ]
    # write_data(bill_list, path)
